package com.examiner.dao;

import com.examiner.bean.Department;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface DepartmentDao extends JpaRepository<Department,Integer>, JpaSpecificationExecutor<Department> {

    Department findByUserName(@Param("userName")String userName);

    /**
     * 根据上级查询
     * @param superior
     * @return
     */
    List<Department> findBySuperior(String superior);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "update department SET eid=?2,examiner=?3 where id=?1", nativeQuery = true)
    void changeExaminer(Integer id, Integer eid, String examiner);

    List<Department> findBySIdAndStype(Integer id, String userName);

    @Query(value = "select id from department where user_name like %?1% and user_name != '部门和职位管理'  ", nativeQuery = true)
    List<Integer> findLikeName(String department);

    List<Department> findBySId(Integer sid);
}
